package ioc

import (
	"booksmart/book/internal/domain"
	"booksmart/book/internal/job"
	"booksmart/book/internal/service"
	"booksmart/book/pkg/logger"
	"context"
	"time"
)

func InitScheduler(l logger.LoggerV1,
	svc service.JobService,
	local *job.LocalExecutor) *job.Scheduler {
	res := job.NewScheduler(svc, l)
	res.Register(local)
	return res
}

func InitLocalExecutor(svc service.RankingService) *job.LocalExecutor {
	executor := job.NewLocalExecutor()
	executor.Register("ranking", func(ctx context.Context, j domain.Job) error {
		ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
		defer cancel()
		return svc.TopN(ctx)
	})

	return executor

}
